<?php
	class Shepherd_AnalysisController extends Sss_Controller_Shepherd
	{
		public function init()
		{
			parent::init();
			$this->checkInstance();
			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$userInformation = new Zend_Session_Namespace(Sss_Ultility_SessionName::ACCOUNT_SESSION_SHEPHERD . $this->getCurrentHandle());
			if (!$userInformation->username) {
				$this->_redirect("/$handle/user/login");
			}
		}

		public function indexAction()
		{
			$handle = $this->getRequest()->getParam('handle', Sss_Ultility_CommonViewParamater::UNDERFINE);
			$userTable = new Shepherd_Model_Mapper_Account();
			$instanceTable  = new Application_Model_Mapper_Instance();
			$instance = $instanceTable->getInstanceByHandle($handle); 
			$userInformation = new Zend_Session_Namespace(Sss_Ultility_SessionName::ACCOUNT_SESSION_SHEPHERD . $this->getCurrentHandle());
			$user = $userTable->getUser($userInformation->username, $instance->instanceid);
			$password = $user->password;
			//check permission of shepherd BI
			if(Sss_Ultility_Common::in_array_field(Sss_Ultility_CommonViewParamater::PER_ANALYSIS, Sss_Ultility_CommonViewParamater::ALL, 'feature', 'action' ,$this->listRole(), true) != 1 ) {
				$this->_redirect("/$handle/user/login");
			}
			//End
			$this->view->assign("birul",URL_SHEPHERD_BI.'/j_spring_security_check?j_password='.$password.'&j_username='.$instance->instanceid.$userInformation->username);
		}
	}
